package
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	
	import root.TestRoot;

	public class TestXML extends TestRoot
	{
		public function TestXML()
		{
			super();
			var name:String = "xiao wang";
			var exam:XML = <person><name>
				{name}
								</name></person>;
			//trace(exam);
			
			var exam2:XML = new XML("<test sex='man'><name>lili</name></test>");
			//trace(exam2);
			
			var exam3:XML = new XML("<root/>");
			exam3.game = "";
			exam3.game.title="suitang";
			exam3.game.title.@maxLen=252;
			exam3.game.testDel = "delete";
			exam3.game.svrIp="127.0.0.1";
			exam3.game.svrPort = 8090;
			exam3["website"] = "www.egame300.net";
			exam3.insertChildBefore(exam3.game[0], <desc>这是一个测试配置</desc>);
			delete exam3.game.testDel;
			//trace(exam3);
			
			var exam4:XML = <example/>;
			exam4.appendChild(<one>1</one>);
			exam4.appendChild(<three>3</three>);
			exam4.prependChild(<two>2</two>);
			exam4.insertChildBefore(exam4.three, 1.5);
			//trace(exam4);
			
			var exam5:XML = <example/>;
			exam5.test = "";
			exam5.test.@string = "test string";
			exam5.test.@boolean = true;
			exam5.test.@int = 555;
			exam5.test.@["array"] = [55,"test", 1.53];
			//trace(exam5);
		
			var exam6:XML = <menu>
								<item label="file">
									<item label="new"/>
								</item>
								<item label="help">
									<item label="about"/>
								</item>
								this is text node
							</menu>;
			//this.walk(exam6);
			
			var exam7:XML = <fruit test="dsdf">
								<name>apple</name>
								<name>orange</name>
								<name1 attr1="aaa" attr2="bbb">oranNNe</name1>
								<name><firstName>lili</firstName></name>
								this is text
							</fruit>;
//			trace(exam7.name[1]);
//			trace(exam7..firstName);
//			trace(exam7.text()[0]);
//			trace(exam7.name1.toUpperCase());
			
			var exam8:XML = <fruit name="apple" color="red"><tst>11</tst></fruit>;
//			for each(var elem:XML in exam8.attributes() ){
//				trace(elem);
//			}
//			trace(exam8.@name);
//			trace(exam8.@["color"]);
//			delete exam7.name1.@attr1;
//			trace(exam7);
			delete exam8.@color;
			//trace(exam8);
			
			
			var loader:URLLoader = new URLLoader();
			var req:URLRequest = new URLRequest("http://127.0.0.1/testXML.xml");
			loader.dataFormat = URLLoaderDataFormat.TEXT;
			loader.addEventListener(Event.COMPLETE, onLoadXMLComplete);
			loader.load(req);
		}
		
		public	function	walk(node:XML):void{
			var list:XMLList = node.elements();
			for each(var elem:XML in list){
				trace(elem.@label);
				this.walk(elem);
			}
		}
		
		public	function	onLoadXMLComplete(evt:Event):void{
			var loader:URLLoader = evt.target as URLLoader;
			var testXML:XML = new XML(loader.data);
			trace(testXML);
		}
	}
}